package com.example.studyplanning.controller;

import com.example.studyplanning.entity.Admin;
import com.example.studyplanning.services.AdminServices;
import com.example.studyplanning.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin")
public class AdminController {
    @Autowired
    private AdminServices adminServices;

    @PostMapping("/login")
    public Result SelectByAdmin(@RequestParam("adminName") String adminName ,@RequestParam("adminPassword") String adminPassword ){
        Result result = new Result();
        Admin adm = adminServices.SelectByAdmin(adminName,adminPassword);
        if(adm !=null){
            result.setCode(200);
            result.setMessage("登录成功");
            result.setObject(adm);
        }else {
            result.setCode(400);
            result.setMessage("登陆失败，请确认账号与密码");
        }
        return result;
    }

    @PostMapping("/update")
    public Result UpdateAdmin(@RequestBody Admin admin){
        Result result = new Result();
        int i = adminServices.UpdateAdmin(admin);
        if(i==1){
            result.setCode(200);
            result.setMessage("更新成功");
        }else {
            result.setCode(400);
            result.setMessage("更新失败");
        }
        return result;
    };
}
